<?php
// 本类由系统自动生成，仅供测试用途
namespace Admin\Controller;

class LinkController extends LoginController {
	public function __construct() {
		parent::__construct ();
		layout ( false );
	}
	
	// 友情链接列表
	function index() {
		$this->db = D ( "Link" );
		if (IS_POST) {
			$arr = $_POST;
			if (! empty ( $arr ['id'] )) {
				$arr ['up_date'] = date ( "Y-m-d H:i:s" );
				$result = $this->db->save ( $arr );
			} else {
				$arr ['user'] = $this->user_id;
				$arr ['creat_date'] = $arr ['up_date'] = date ( "Y-m-d H:i:s" );
				$result = $this->db->add ( $arr );
			}
			echo true;
			exit ();
		}
		$count = $this->db->count (); // 查询满足要求的总记录数 $map表示查询条件
		$Page = $this->getPage ( $count );
		$show = $Page->show ();
		$list = $this->db->limit ( $Page->firstRow . ',' . $Page->listRows )->select ();
		$this->assign ( array (
				'show' => $show,
				'list' => $list 
		) );
		$this->display ();
	}
	
	// 删除友情链接
	public function linkDe() {
		$this->db = D ( 'Link' );
		if (IS_POST) {
			echo $result = $this->db->delete ( $_POST ['id'] );
		}
	}
	
	// 获取友情链接
	public function linkGetOne() {
		$this->db = D ( 'Link' );
		if (IS_POST) {
			$id = $_POST ['id'];
			$data = $this->db->find ( $id );
			$this->ajaxReturn ( $data );
		}
	}
	/**
	 * 链接排序
	 * 
	 * @access public
	 * @param int $id
	 *        	链接id
	 */
	public function listorder() {
		if (IS_POST) {
			$arr = $_POST;
			$arr = $arr ['listorder'];
			$this->db = D ( "Link" );
			foreach ( $arr as $key => $r ) {
				$this->db->where ( "id=$key" )->save ( array (
						'listorder' => $r 
				) );
			}
			$this->index();
		}
	}
}